define(['jquery', 'bootstrap', 'backend', 'table', 'form'], function ($, undefined, Backend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置

            Table.api.init({
                extend: {
                    index_url: 'user_smrz/index' + location.search,
                    add_url: 'user_smrz/add',
                    edit_url: 'user_smrz/edit',
                    del_url: 'user_smrz/del',
                    multi_url: 'user_smrz/multi',
                    table: 'user_smrz',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('Id')},
                        {field: 'uid', title: __('Uid')},
                        {field: 'image', title: __('Image'), events: Table.api.events.image, formatter: Table.api.formatter.image},
                        {field: 'gllx', title: __('Gllx')},
                        {field: 'dawe', title: __('Dawe')},
                        {field: 'bume', title: __('Bume')},
                        {field: 'zzfg', title: __('Zzfg')},
                        {field: 'fwid', title: __('Fwid')},
                        {field: 'username', title:'姓名'},
                        {field: 'mobile', title:'电话'},
                        {field: 'fwid', title: __('Fwid')},
                        {field: 'status', title: __('Status')},
                        {field: 'operate', title: __('Operate'), table: table,    buttons: [
                                {name: 'pass', text: '通过', title: '通过', icon:'fa fa-post', classname:'btn btn-xs btn-primary ', url: 'user_smrz/examine?status=1'},
                                {name: 'fail', text: '驳回', title: '驳回', icon:'fa fa-post', classname:'btn btn-xs btn-primary ', url: 'user_smrz/examine?status=2'}
                            ],
                            events: Table.api.events.operate, formatter: Table.api.formatter.operate,
                            formatter: function (value, row, index) { //隐藏自定义按钮
                                var that = $.extend({}, this);
                                var table = $(that.table).clone(true);
                                if(row.status!=='待审核') {
                                    $(table).data("operate-pass", null);  //隐藏按钮操作 video为自定义按钮的name
                                    $(table).data("operate-fail", null);  //隐藏按钮操作 video为自定义按钮的name
                                }
                                that.table = table;
                                return Table.api.formatter.operate.call(that, value, row, index);
                            },}
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
